﻿Imports GestionFicheClient.CnxMySql
Public Class gestionClient

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Dim rep = MessageBox.Show("Voulez vous vraiment ajouter ce client?...", "Confirmation", MessageBoxButtons.YesNo)
                If rep = DialogResult.Yes Then

            Dim nc, tc, nr, r, cp, v As String

            nc = TextBox1.Text
            tc = TextBox3.Text
            nr = TextBox4.Text
            r = TextBox2.Text
            cp = TextBox5.Text
            v = TextBox6.Text



            Executer_Requete_Action("INSERT INTO `client`( `nomClient`, `telClient`, `numRueClient`, `nomRueClient`, `cpVilleClient`, `villeClient`) VALUES (" & nc & "," & tc & "," & nr & "," & r & "," & cp & "," & v & ")")

            MessageBox.Show("Client Ajouté...!", "Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information)

                    

                Else


                End If
        Me.Close()

    End Sub

    Private Sub gestionClient_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Dim rep = MessageBox.Show("Voulez vous vraiment ajouter cette intervention ?...", "Confirmation", MessageBoxButtons.YesNo)
        If rep = DialogResult.Yes Then
            Dim chk As CheckBox


            Dim y = gestionFiches.DateTimePicker1.Value.Year
            Dim m = gestionFiches.DateTimePicker1.Value.Month
            Dim d = gestionFiches.DateTimePicker1.Value.Day
            Dim dateEntree = y & "-" & m & "-" & d

            Dim ni, dt, tc, ti, com, nc, ref, id, md, ad As String
            ni = gestionFiches.txtBoxNumInt.Text
            dt = dateEntree
            tc = gestionFiches.cmbBoxTech.ValueMember
            ti = gestionFiches.cmbBoxTypeInt.ValueMember
            For Each ctrl As Control In gestionFiches.grpBoxOs.Controls


                If TypeOf ctrl Is CheckBox Then

                    chk = ctrl

                    If chk.Checked = True Then

                        ti = ti & "," & chk.Text

                    End If
                End If
            Next ctrl
            com = gestionFiches.txtBoxCom.Text
            nc = gestionFiches.txtBoxNomCli.Text
            tc = gestionFiches.txtBoxTelCli.Text
            ref = gestionFiches.txtBoxRef.Text
            id = gestionFiches.txtBoxIdent.Text
            md = gestionFiches.txtBoxMdp.Text
            ad = gestionFiches.txtBoxFact.Text


            Executer_Requete_Action("Insert into Interventions Values ( " & ni & ", " & dt & "," & tc & "," & ti & ",'" & com & "','" & nc & "','" & ref & "','" & id & "','" & md & "','" & ad & "' ")

            MessageBox.Show("Intervention Ajoutée...!", "Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information)
            gestionFiches.DataGridView1.DataSource = Executer_Requete_Select("Select idIntervention as Numero_Fiche, dateReception as Date_de_Reception,nomTechnicien as Technicien, typeIntervention as Travail_à_effectuer, commentaire, nomClient as Client,telclient as Telephone_Client, refEquipement as Equipement,identifiant, mdp as Mot_de_passe,adresseFacturation From interventions, techniciens, client where (Client.idClient = interventions.numclient) and (techniciens.idTechnicien = interventions.numtechnicien)")

            gestionFiches.rafraichir_textbox()
            'rafraichir()
            gestionFiches.Button5.Text = "Ajouter"
        Else
            gestionFiches.Button5.Text = "Ajouter"
            'rafraichir()
        End If

    End Sub

    Private Sub gestionClient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
    End Sub
End Class